

#import "BusinessGatheringViewController.h"
#import "sxview.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "addhuiyuanViewController.h"
#import "GatheringListCell.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "UIButton+WebCache.h"
#import "huiyuanDetailsViewController.h"
#import "GetProductListViewController.h"
#import "TheLoginViewController.h"
#import "shouyingViewController.h"

#import "BusinessGatheringDetailViewController.h"
@interface BusinessGatheringViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)UIDatePicker* da;

@end

@implementation BusinessGatheringViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*orderNo;
    NSMutableArray*orderid;
    NSMutableArray*orderType;
    NSMutableArray*payAmount;
    NSMutableArray*payType;
    NSMutableArray*tradeNo;
    NSMutableArray*status;
    NSMutableArray* remark;
    NSMutableArray* createDate;
    NSMutableArray* image;
    NSString *result;
    int pageNumber;
      BOOL saveAccount;
    NSMutableArray*typeName;
    NSMutableArray*typeCode;
    NSMutableArray*isSingle;
    NSMutableArray*congzhicurrent;
    NSMutableArray*current;
    NSMutableArray*dataType;
    NSMutableArray *searchBeans;
    NSMutableArray*itemValue;
    NSMutableArray*itemName;
    NSMutableArray*items;
    UITextField*openTimeTextFied;
    UITextField*closeTimeTextFied;
    sxview*daogouView;
    UIView*view;
    UITableView *table_list;
    UIScrollView*mainScroll;
    NSMutableArray* arrrss;
    UIButton*shaixuanBtn;
    UIButton*  sxBtn;
    
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 0.5)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    
    self.title=@"历史账单";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    
    

}

-(void)addProduct:(UIButton*)sender{
    
}


- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    [self addFooter];
     [self addheader];
     commdity=[HAODEsingleton shared];
    
    
    
    commdity=[HAODEsingleton shared];
    commdity.opentime=nil;
    commdity.closeTime=nil;
    commdity.content3=@"";
//    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) ];
    _table.delegate = self;
    _table.dataSource = self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_table];
       
   
    
        sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0,  60/2, 60/2)];
        [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
        [sxBtn addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:sxBtn];
        self.navigationItem.rightBarButtonItem = myBtnBtn;

    
    [self add];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"gathering" forKey:@"filterType"];
   //NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/AdvancedFilterList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====－－－－－－－%@",severDataDict.dataDict);
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                typeCode=[[NSMutableArray alloc]init];
                typeName=[[NSMutableArray alloc]init];
                items=[[NSMutableArray alloc]init];
                isSingle=[[NSMutableArray alloc]init];
                current=[[NSMutableArray alloc]init];
                congzhicurrent=[[NSMutableArray alloc]init];
                dataType=[[NSMutableArray alloc]init];
                for (NSDictionary* dicc in arrr )
                {
                    [typeName addObject:[dicc valueForKey:@"typeName"]];
                    [typeCode addObject:[dicc valueForKey:@"typeCode"]];
                    [items addObject:[dicc valueForKey:@"items"]];
                    [isSingle addObject:[dicc valueForKey:@"isSingle"]];
                    
                    [congzhicurrent addObject:[dicc valueForKey:@"current"]];
                    [current addObject:[dicc valueForKey:@"current"]];
                    [dataType addObject:[dicc valueForKey:@"dataType"]];
                    
                    for (NSDictionary* dicc1 in items )
                    {
                        [itemName addObject:[dicc1 valueForKey:@"itemName"]];
                        [itemValue addObject:[dicc1 valueForKey:@"itemValue"]];
                        
                    }
                    
                    
                }
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
}
-(void)add{
    
    pageNumber = 1;
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"1" forKey:@"pageIndex"];
    [param setValue:@"20" forKey:@"pageSize"];
    
    [param setValue:searchBeans forKey:@"searchBeans"];
    
    NSLog(@"====%@",param);

    
    [HttpRequest requestData:@"Business/Gathering/List" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                if (searchBeans.count>0) {
                    
                    
                    [sxBtn setImage:[UIImage imageNamed:@"shaixuan_hight"] forState:UIControlStateNormal];
                    
                    
                }else{
                   
                    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
                }
                

                orderNo= [[NSMutableArray alloc] init];
                orderid= [[NSMutableArray alloc] init];
                orderType= [[NSMutableArray alloc] init];
                payAmount= [[NSMutableArray alloc] init];
                tradeNo= [[NSMutableArray alloc] init];
                status= [[NSMutableArray alloc] init];
                remark = [[NSMutableArray alloc] init];
                createDate = [[NSMutableArray alloc] init];
                image= [[NSMutableArray alloc] init];
                
                payType= [[NSMutableArray alloc] init];
                

                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [orderNo addObject:[dicc valueForKey:@"orderNo"]];
                    [orderid addObject:[dicc valueForKey:@"id"]];
                    [orderType addObject:[dicc valueForKey:@"orderType"]];
                    [tradeNo addObject:[dicc valueForKey:@"tradeNo"]];
                    [payAmount addObject:[dicc valueForKey:@"payAmount"]];
                    [status addObject:[dicc valueForKey:@"status"]];
               
                    [createDate addObject:[dicc valueForKey:@"createDate"]];
                    [payType addObject:[dicc valueForKey:@"payType"]];
                    
                    
                    
                }
                 [_table reloadData];
                
            }else{
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
                    [self.navigationController pushViewController:detailViewController animated:YES];
                }
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
   
    
    
    
}





//上拉刷新
- (void)addFooter
{
    
    
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        if (Token ==nil) {
            Token=@"dd";
        }
        NSMutableDictionary *param = [NSMutableDictionary new];
        [param setValue:Token forKey:@"tokenId"];
        [param setValue:@"1" forKey:@"pageIndex"];
        [param setValue:@"20" forKey:@"pageSize"];
        [param setValue:[NSString stringWithFormat:@"%d" ,pageNumber] forKey:@"pageIndex"];
        [param setValue:searchBeans forKey:@"searchBeans"];
        
        NSLog(@"====%@",param);
        
        
        [HttpRequest requestData:@"Business/Gathering/List" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
                NSLog(@"====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                                        
                    
                    
                    
                    NSMutableArray* arrr=[[NSMutableArray alloc]init];
                    arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (NSDictionary* dicc in arrr )
                    {
                        [orderNo addObject:[dicc valueForKey:@"orderNo"]];
                        [orderid addObject:[dicc valueForKey:@"id"]];
                        [orderType addObject:[dicc valueForKey:@"orderType"]];
                        [tradeNo addObject:[dicc valueForKey:@"tradeNo"]];
                        [payAmount addObject:[dicc valueForKey:@"payAmount"]];
                        [status addObject:[dicc valueForKey:@"status"]];
                        
                        [createDate addObject:[dicc valueForKey:@"createDate"]];
                        [payType addObject:[dicc valueForKey:@"payType"]];
                 
                    }
                    [_table reloadData];
                    
                }else{
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
                        [self.navigationController pushViewController:detailViewController animated:YES];
                    }
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];

        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:2.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
    
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView == table_list) {
        return [typeCode count];
    }
    return [orderNo count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    
    static NSString *CellIdentifier = @"Cell";
    
    GatheringListCell* cell = (GatheringListCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"GatheringListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    
    
    if (tableView == _table) {
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    [cell.image.layer setCornerRadius:6.0];
    [cell.image.layer setBorderWidth:0.3];
    [cell.image.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [cell.image.layer setBorderColor:colorref2];//边框颜色
    
    
    
   
    
    
    if ([[payType objectAtIndex:indexPath.row]isEqualToString:@"wx_pay_scan"]) {
         cell.payType.text=[NSString stringWithFormat:@"%@",  @"微信扫码支付"];
         [cell.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"weixinkuang"]];
    }
    if ([[payType objectAtIndex:indexPath.row]isEqualToString:@"CashPay"]) {
        cell.payType.text=[NSString stringWithFormat:@"%@",  @"现金支付"];
         [cell.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"xianjin"]];
    }
    if ([[payType objectAtIndex:indexPath.row]isEqualToString:@"IboxPay"]) {
        cell.payType.text=[NSString stringWithFormat:@"%@",  @"盒子支付"];
         [cell.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"shuakas"]];
    }
        if ([[payType objectAtIndex:indexPath.row]isEqualToString:@"AliQrPay"]) {
            cell.payType.text=[NSString stringWithFormat:@"%@",  @"支付宝支付"];
            [cell.image setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"zhifubaos"]];
        }
    cell.payType.textColor=[UIColor blackColor];
    
    cell.createDate.textColor=zhonghuiColor;
   
    NSRange range={0,16};
    NSString* string =[[NSString stringWithFormat:@"%@",[createDate objectAtIndex:indexPath.row]] substringWithRange:range];
    cell.createDate.text =[NSString stringWithFormat:@"%@",string];

    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[payAmount objectAtIndex:indexPath.row]];

    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];

    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
//    cell.payAmount.frame=CGRectMake(ScreenWidth-200, 15, 180, 16);
//    cell.payAmount.textAlignment=NSTextAlignmentRight;
    cell.payAmount.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];
    cell.payAmount.font=[UIFont systemFontOfSize:16];
    cell.payAmount.textColor=[UIColor blackColor];


//    cell.status.frame=CGRectMake(ScreenWidth-200, 35, 180, 16);
//    cell.status.textAlignment=NSTextAlignmentRight;
    if ([[status objectAtIndex:indexPath.row]isEqualToString:@"Y"]) {
        cell.status.text =[NSString stringWithFormat:@"%@",@"交易成功"];
        cell.status.textColor=shenhuicolor;
   

    
    }else{
    cell.status.text =[NSString stringWithFormat:@"%@",@"交易失败"];

    cell.status.textColor=hongsecolor;
    }



    if ([[orderType objectAtIndex:indexPath.row]isEqualToString:@"order"]) {
        cell.orderType.text =[NSString stringWithFormat:@"%@",@"订单"];
        cell.orderType.textColor=[UIColor whiteColor];
         cell.orderType.backgroundColor=luseColor;
        
        
    }
    if ([[orderType objectAtIndex:indexPath.row]isEqualToString:@"service"]) {
        cell.orderType.text =[NSString stringWithFormat:@"%@",@"服务"];
        cell.orderType.textColor=[UIColor whiteColor];
        cell.orderType.backgroundColor=huangtitleColor;
        
    }
    
    if ([[orderType objectAtIndex:indexPath.row]isEqualToString:@"other"]) {
        cell.orderType.text =[NSString stringWithFormat:@"%@",@"自定义"];
        cell.orderType.textColor=[UIColor whiteColor];
        cell.orderType.backgroundColor=zhonghuiColor;
        
        
    }
    
    
    
    if (orderType.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 80-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    if (orderType.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 80-0.35, ScreenWidth, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    }

    if (tableView == table_list) {
        
         cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
        cell.textLabel.font=[UIFont systemFontOfSize:16];
        cell.textLabel.textColor=qianheicolor;
        
        
        if(commdity.content3.length> 0)
            
        {
            if  ([[typeName objectAtIndex:indexPath.row]isEqualToString:commdity.content2]){
                
                
                
                
                if (![commdity.content3 isEqualToString:@"自定义"]) {
                    cell.detailTextLabel.text =commdity.content3;
                    
                    for (int i = 0; i<[[items objectAtIndex:indexPath.row]count]; i++) {
                        
                        if  ([[[[items objectAtIndex:indexPath.row]objectAtIndex:i]objectForKey:@"itemName"] isEqualToString:commdity.content3]){
                            
                            [current replaceObjectAtIndex:indexPath.row withObject:[[items objectAtIndex:indexPath.row]objectAtIndex:i]];
                            
                        }else{
                        }
                        
                    }
                    
                    
                }else{
                    
                    cell.detailTextLabel.text =[NSString stringWithFormat:@"%@~%@",openTimeTextFied.text,closeTimeTextFied.text];
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    
                    [dic setValue:[NSString stringWithFormat:@"%@",@"Y"]forKey:@"isCustom"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"Y"] forKey:@"isRange"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"自定义"] forKey:@"itemName"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"other"] forKey:@"itemValue"];
                    [dic setValue:openTimeTextFied.text forKey:@"minValue"];
                    [dic setValue:closeTimeTextFied.text forKey:@"maxValue"];
                    
                    
                    
                    [current replaceObjectAtIndex:indexPath.row withObject:dic];
                    
                    
                    
                }
                
                
                NSLog(@"ffff====%@",typeCode);
                NSLog(@"====%@",isSingle);
                NSLog(@"====%@",current);
                
                
            }
            
            
        }else{
            
            
            cell = [[GatheringListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
            cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
            cell.textLabel.font=[UIFont systemFontOfSize:16];
            cell.textLabel.text =[NSString stringWithFormat:@"%@", [typeName objectAtIndex:indexPath.row]];
             UIButton*jiantou = [[UIButton alloc]init];
            jiantou.frame = CGRectMake(ScreenWidth-30,7.5, 30, 30);
            [jiantou setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
            cell.accessoryView=jiantou;
           cell.detailTextLabel.text = [[congzhicurrent objectAtIndex:indexPath.row]objectForKey:@"itemName"];
            
        }
        
        cell.detailTextLabel.textColor=luseColor;
        if (typeName.count !=indexPath.row+1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
        if (typeName.count ==indexPath.row+1) {
           UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
    }
    return cell;
}



- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table_list) {
        return  55;
    }
    
    
    return  80;
    
}




#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == table_list) {
        commdity.content2=typeName[indexPath.row];
        
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        [mainScroll removeFromSuperview];
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"Token"];
        if (Token ==nil) {
            Token=@"dd";
        }
        NSMutableDictionary *param = [NSMutableDictionary new];
        [param setValue:Token forKey:@"Token"];
        
        mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(45, 0, ScreenWidth-45, ScreenHeight)];
        mainScroll.delegate = self;
        mainScroll.userInteractionEnabled = YES;
        mainScroll.scrollEnabled = YES;
        mainScroll.showsVerticalScrollIndicator = FALSE;
        mainScroll.showsHorizontalScrollIndicator = FALSE;
        mainScroll.backgroundColor=[UIColor whiteColor];
        [self.window addSubview:mainScroll];
        // 手势
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad1)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [mainScroll addGestureRecognizer:singleFingerOne];
        UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
        title.text=typeName[indexPath.row];
        title.textAlignment=NSTextAlignmentCenter;
        [mainScroll addSubview:title];
        
        UIButton*quxiao1 = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
        [quxiao1 setTitle:@"取消" forState:UIControlStateNormal];
        [quxiao1 setTitleColor:zhonghuiColor forState:UIControlStateNormal];
        quxiao1.titleLabel.font=[UIFont systemFontOfSize:16];
        [quxiao1 addTarget:self action:@selector(quxiao1:) forControlEvents:UIControlEventTouchUpInside];
        [mainScroll addSubview:quxiao1];
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight-0.35, ScreenWidth-45, 0.35)];
        line.backgroundColor=qianhuicolor;
        [mainScroll addSubview:line];
        
        
        arrrss=[[NSMutableArray alloc]init];
        
        arrrss=[[items objectAtIndex:indexPath.row] mutableCopy];
        
        NSLog(@"%@",arrrss);
        if (arrrss.count>0) {
            
            for (int i = 0; i<arrrss.count; i++) {
                
                daogouView = [[sxview alloc]initWithFrame:CGRectMake(15, NavHeight+(55*i), ScreenWidth-45, 55)];
                
                daogouView.buttonView.titleLabel.textAlignment=NSTextAlignmentRight;
                daogouView.buttonView.titleLabel.font=[UIFont systemFontOfSize:16];
                daogouView.buttonView.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [daogouView.buttonView setTitle: [[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] forState:UIControlStateNormal];
                daogouView.buttonView.backgroundColor=[UIColor whiteColor];
                daogouView.buttonView.tag=i;
                [daogouView.buttonView setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                [daogouView.buttonView setTitleColor:qianheicolor forState:0];

                
                
                
                [mainScroll addSubview:daogouView];
                
                if ([[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] isEqualToString:@"自定义"]) {
                    
                    if ([typeName[indexPath.row] isEqualToString:@"时间"]) {
                        
                        [daogouView.buttonView setTitleColor:luseColor forState:0];
                        
                        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth-45, 48)];
                        [login setTitle:@"确认" forState:UIControlStateNormal];
                        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                        login.backgroundColor=luseColor;
                        [login addTarget:self action:@selector(queren:) forControlEvents:UIControlEventTouchUpInside];
                        [mainScroll addSubview:login];
                        
                        
                        
                        
                        _da = [[UIDatePicker alloc] init];
                        [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
                        _da.datePickerMode = UIDatePickerModeDate;
                        _da.backgroundColor=[UIColor whiteColor];
                        
                        
                        openTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(50,  daogouView.bottom-55, 110,  55)];
                        openTimeTextFied.borderStyle = UITextBorderStyleNone;
                        openTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                        openTimeTextFied.textColor=[UIColor blackColor];
                        openTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                        openTimeTextFied.tag=2;
                        openTimeTextFied.placeholder = @"开始时间"; //默认显示的字
                        openTimeTextFied.delegate = self;
                        openTimeTextFied.text=commdity.opentime;
                        openTimeTextFied.textAlignment=NSTextAlignmentCenter;
                        [openTimeTextFied setUserInteractionEnabled:YES];
                        //openTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                        [mainScroll addSubview:openTimeTextFied];
                        
                        UILabel* fuhao=[[UILabel alloc]initWithFrame:CGRectMake(openTimeTextFied.right, daogouView.bottom-55,15,55)];
                        fuhao.text=[NSString stringWithFormat:@"%@", @"～"];
                        fuhao.font=[UIFont systemFontOfSize:contenfot];
                        fuhao.textColor=[UIColor blackColor];
                        [mainScroll addSubview:fuhao];
                        
                        closeTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(fuhao.right-5,  daogouView.bottom-55, 110,  55)];
                        closeTimeTextFied.borderStyle = UITextBorderStyleNone;
                        closeTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                        closeTimeTextFied.textColor=[UIColor blackColor];
                        closeTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                        closeTimeTextFied.tag=3;
                        closeTimeTextFied.placeholder = @"结束时间"; //默认显示的字
                        closeTimeTextFied.textAlignment=NSTextAlignmentCenter;
                        closeTimeTextFied.text= commdity.closeTime;
                        closeTimeTextFied.delegate = self;
                        [closeTimeTextFied setUserInteractionEnabled:YES];
                        //                                   closeTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                        [mainScroll addSubview:closeTimeTextFied];
                        //[_da setAccessibilityLanguage:@"Chinese"];
                        
                        openTimeTextFied.inputView = _da;
                        closeTimeTextFied.inputView = _da;
                        
                    }
                    
                    
                }else{
                    [daogouView.buttonView addTarget:self action:@selector(daogouView:) forControlEvents:UIControlEventTouchUpInside];
                }
                
                if ([[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] isEqualToString:cell.detailTextLabel.text]) {
                    
                    UIImageView*image11=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50-60, 16.5, 18, 18)];
                    image11.image=[UIImage imageNamed:@"huiyuan_gou"];
                    
                    [daogouView addSubview:image11];
                    
                }
            }
            
            
            
            
            [mainScroll setContentSize:CGSizeMake(ScreenWidth-45, daogouView.bottom)];
        }
        
        
        
        
        
    }else{
        
        
        commdity.gid=orderid[indexPath.row];
        BusinessGatheringDetailViewController *detailViewController = [[BusinessGatheringDetailViewController alloc] init];
        [self.navigationController pushViewController:detailViewController animated:YES];

        
    }
    
    
}

- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    
    
    
    
    if ([openTimeTextFied isFirstResponder])
    {
        openTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
        
        
    }else{
        
        closeTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }
    
    
}

-(void)quxiao1:(UIButton*)sender{
    
    
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    
    [mainScroll removeFromSuperview];
    
}
-(void)queren:(UIButton*)sender{
    
    if ([ openTimeTextFied.text length] < 1)
    {
        [self showAlertMessage:@"请选择开始时间"];
    }
    else
    {
        
        if ([closeTimeTextFied.text length] <1)
        {
            [self showAlertMessage:@"请选择结束时间"];
        }
        else{
            
            
            [mainScroll removeFromSuperview];
            commdity.content3=@"自定义";
            [table_list reloadData];
            commdity.opentime=openTimeTextFied.text;
            commdity.closeTime=closeTimeTextFied.text;
        }}
    
    
}

-(void)daogouView:(UIButton*)sender{
    
    commdity.opentime=nil;
    commdity.closeTime=nil;
    
    commdity.content3=sender.titleLabel.text;
    [mainScroll removeFromSuperview];
    [table_list reloadData];
    
    
    
}


-(void)sxuan:(UIButton*)sender{
    
    
    if(commdity.content3.length> 0){
        
        
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, ScreenHeight)];
        view.backgroundColor=[UIColor blackColor];
        view.alpha=0.5;
        [self.window makeKeyAndVisible];
        [self.window addSubview:view];
        
        
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [view addGestureRecognizer:singleFingerOne];
        
        table_list.frame=CGRectMake(45, 0, ScreenWidth-45, ScreenHeight);
        [self.window addSubview:table_list];
        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(45, ScreenHeight-48, ScreenWidth-45, 48)];
        [login setTitle:@"确认" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [self.window addSubview:login];
        
        
    }else{
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, ScreenHeight)];
        view.backgroundColor=[UIColor blackColor];
        view.alpha=0.5;
        [self.window makeKeyAndVisible];
        [self.window addSubview:view];
        
        
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [view addGestureRecognizer:singleFingerOne];
        
        
//         saveAccount1=NO;
        table_list = [[UITableView alloc]initWithFrame:CGRectMake(45, 0, ScreenWidth-45, ScreenHeight) style:UITableViewStylePlain];

        table_list.delegate = self;
        table_list.dataSource = self;
        table_list.rowHeight = 60;
        table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.window addSubview:table_list];
        
        
        UIView*Header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth-50, NavHeight)];
        Header.backgroundColor=[UIColor whiteColor];
        table_list.tableHeaderView=Header;
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight, ScreenWidth-50, 0.35)];
        line.backgroundColor=qianhuicolor;
        [Header addSubview:line];
        
        UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
        title.text=@"筛选";
        title.textAlignment=NSTextAlignmentCenter;
        [Header addSubview:title];
        
        UIButton*quxiao = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
        [quxiao setTitle:@"取消" forState:UIControlStateNormal];
        [quxiao setTitleColor:zhonghuiColor forState:UIControlStateNormal];
        quxiao.titleLabel.font=[UIFont systemFontOfSize:16];
        [quxiao addTarget:self action:@selector(quxiao:) forControlEvents:UIControlEventTouchUpInside];
        [Header addSubview:quxiao];
        
        UIButton*chongzhi = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-50-60, 20, 50, NavHeight-20)];
        [chongzhi setTitle:@"重置" forState:UIControlStateNormal];
        [chongzhi setTitleColor:luseColor forState:UIControlStateNormal];
        chongzhi.titleLabel.font=[UIFont systemFontOfSize:16];
        [chongzhi addTarget:self action:@selector(chongzhi:) forControlEvents:UIControlEventTouchUpInside];
        [Header addSubview:chongzhi];
        
        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(45, ScreenHeight-48, ScreenWidth-45, 48)];
        [login setTitle:@"确认" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [self.window addSubview:login];
    }
}

-(void)chongzhi:(UIButton*)sender{
    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    commdity.content3=@"";
    current= [congzhicurrent mutableCopy];
    NSLog(@"----------%@",current);
   
    [table_list reloadData];
    
}

-(void)quxiao:(UIButton*)sender{
    
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    
    
}

-(void)login:(UIButton*)sender{
    
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    
    searchBeans=[NSMutableArray array];
    
    for (int i=0; i<current.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSString *typeCode1 = [typeCode objectAtIndex:i];
        NSString *isSingle1 = [isSingle objectAtIndex:i];
        NSString *typeName1 = [typeName objectAtIndex:i];
        NSString *dataType1 = [dataType objectAtIndex:i];
        NSMutableArray* currentarray=[NSMutableArray array];
        [currentarray insertObject:[current objectAtIndex:i] atIndex:0];
        [dic setValue:[NSString stringWithFormat:@"%@",typeCode1]forKey:@"typeCode"];
        [dic setValue:[NSString stringWithFormat:@"%@",isSingle1] forKey:@"isSingle"];
        [dic setValue:[NSString stringWithFormat:@"%@",typeName1] forKey:@"typeName"];
        [dic setValue:[NSString stringWithFormat:@"%@",dataType1] forKey:@"dataType"];
        [dic setValue:currentarray forKey:@"items"];
        [searchBeans addObject:dic];
    }
    
    NSLog(@"====%@",searchBeans);
    if ([commdity.content3 isEqualToString:@""]) {
        searchBeans=nil;
    }
    
    [self add];
    
    
}
-(void)closeKeyBoad1{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
}
-(void)closeKeyBoad{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    saveAccount=YES;
    
//    [searchTextField resignFirstResponder];
}






//-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return  UITableViewCellEditingStyleDelete;
//    
//}
//- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
//    return YES;
//}
//
//
//-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
//
//{
//    
//    return @"删除";
//    
//}
//- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//    
//    //    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    //    NSString* Token = [user objectForKey:@"tokenId"];
//    //    if (Token ==nil) {
//    //        Token=@"dd";
//    //    }
//    //    NSMutableDictionary *param = [NSMutableDictionary new];
//    //    [param setValue:Token forKey:@"tokenId"];
//    //    [param setValue:@[shopCartIds[indexPath.row]] forKey:@"shopCartIds"];
//    //
//    //
//    //    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
//    //
//    //
//    //    [HttpRequest requestData:@"Business/ShopCart/Remove" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
//    //        if (isSuccess) {   NSLog(@"-----------%@", severDataDict.dataDict);
//    //            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
//    //                [Global hideProgressHUDInternal:self.view];
//    //                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//    //
//    //                [Global showTextHudSub:requestResultStr view:self.view];
//    //
//    //                [self add];
//    //
//    //
//    //            }else{
//    //                [Global hideProgressHUDInternal:self.view];
//    //                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
//    //                [Global showTextHudSub:requestResultStr view:self.view];
//    //            }
//    //
//    //        }
//    //        else
//    //        {
//    //            [Global hideProgressHUDInternal:self.view];
//    //            NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
//    //            [Global showTextHudSub:@"连接失败" view:self.view];
//    //        }
//    //
//    //    }];
//    
//    
//}



//清空购物车
-(void)empty:(UIButton*)sender{
    
    
    UIAlertView*alt1 = [[UIAlertView alloc] initWithTitle:@"是否清空购物车！" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    [alt1 show];
    
    
}



- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

//上拉刷新
- (void)addheader
{
    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {

        //        [Global hideProgressHUDInternal:mainScroll];
        searchBeans=nil;
        commdity.content3=@"";
        [self add];
        //这里的RefreshView就是footer
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        //        NSLog(@"%@--->正在刷新", mainScroll.class);
    };

}

@end
